package cn.hesion.leetcode;
/**
 * ClassName: WiggleSort <br/>
 * Description: <br/>
 * date: 2022/6/4 6:44<br/>
 *
 * @author Hesion<br />
 * @version
 * @since JDK 1.8
 */

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * 面试题 10.11. 峰与谷
 *
 * @author: hesion
 * @create: 2022-06-04 06:44
 **/
public class WiggleSort {
    public void wiggleSort(int[] nums) {
        Arrays.sort(nums);
        List<Integer> tmp = new ArrayList<Integer>();
        int l = 0, r = nums.length - 1;
        while (l < r) {
            tmp.add(nums[r--]);
            tmp.add(nums[l++]);
        }
        if(nums[l]==nums[r]){
            tmp.add(nums[l]);
        }
        for (int i = 0; i < nums.length; i++) {
            nums[i] = tmp.get(i);
        }
    }
}
